<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.interfaces.zwgk.utils.InvokeHelper" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="baseBean" class="weaver.general.BaseBean"/>
<%
    JSONObject returnJson = new JSONObject();
    String requestid = request.getParameter( "requestid" );
    String tablename = "formtable_main_16";
    int formid = 16;
    out.print( ">>>>>>WeaPayContractAction>>>>>" + requestid+"<br/>" );
    try {
        rs.executeQuery( "select * from " + tablename + " where requestid=?", requestid );
        if (rs.next()) {
            String mainid = Util.null2String( rs.getString( "id" ) );
            out.print( ">>>>>mainid>>>>" + mainid+"<br/>" );
            JSONObject jsonData = new JSONObject();
            //企业编号
            jsonData.put( "companyCode", "01-0070-202202-001" );
            //合同编号
            jsonData.put( "contractCode", Util.null2String( rs.getString( "htbh1" ) ) );
            //合同名称
            jsonData.put( "contractName", Util.null2String( rs.getString( "htmc" ) ) );
            jsonData.put( "contractSecretLev", Util.null2String( rs.getString( "htmj" ) ) );
            //采购方
            jsonData.put( "purchaserName", Util.null2String( rs.getString( "cgf" ) ));
            //采购方统一社会信用代码
            jsonData.put( "purchaserCode", Util.null2String( rs.getString( "cgrdm" ) ) );
            //合同履约状态
            jsonData.put( "contKeepStatus", Util.null2String( rs.getString( "lyztwb" ) ) );
            //采购方统一社会信用代码
            jsonData.put( "purchaseUse", Util.null2String( rs.getString( "cgrdm" ) ) );
            //资金来源
            jsonData.put( "capitalSource", Util.null2String( rs.getString( "zjlywb" ) ) );
            //计价方式
            jsonData.put( "pricingManner", Util.null2String( rs.getString( "jjfswb" ) ) );
            //技术权重
            jsonData.put( "technicalWeight", Util.null2String( rs.getString( "jsqc" ) ) );
            //商务权重
            jsonData.put( "businessWeight", Util.null2String( rs.getString( "swqc" ) ) );
            //付款方式
            jsonData.put( "payWay", Util.null2String( rs.getString( "fkfswb" ) ) );
            //采购方式
            jsonData.put( "purchaseWay", Util.null2String( rs.getString( "cgfswb" ) ) );
            //采购组织形式
            jsonData.put( "purchaseOrgForm", Util.null2String( rs.getString( "cgzzxswb" ) ) );
            //电子招标平台
            jsonData.put( "procurementPlatform", Util.null2String( rs.getString( "dzzbpt" ) ) );
            //合同金额
            jsonData.put( "contractAmount", Util.null2String( rs.getString( "htje" ) ) );
            //币种
            jsonData.put( "currency", Util.null2String( rs.getString( "bzwb" ) ) );
            //汇率
            jsonData.put( "exchangeRate", Util.null2String( rs.getString( "hl" ) ) );
            //签订时间
            jsonData.put( "signTime", Util.null2String( rs.getString( "qdsj" ) ) );
            //生效时间
            jsonData.put( "effectiveDate", Util.null2String( rs.getString( "sxsj" ) ) );
            //开始时间
            jsonData.put( "startTime", Util.null2String( rs.getString( "htkssj" ) ) );
            //结束时间
            jsonData.put( "endTime", Util.null2String( rs.getString( "htjssj" ) ) );
            //履约地点
            jsonData.put( "fulfillmentPlace", Util.null2String( rs.getString( "lyddwb" ) ) );
            //履约评价
            jsonData.put( "supplierEvaluation", Util.null2String( rs.getString( "lypj" ) ) );
            //是否招标
            jsonData.put( "tender", Util.null2String( rs.getString( "sfzb" ) ) );
            //采购包和标段编号
            jsonData.put( "blockNumber", Util.null2String( rs.getString( "cgbhbdbh" ) ) );
            //采购包和标段名称
            jsonData.put( "blockName", Util.null2String( rs.getString( "cgbhbdmc" ) ) );
            //采购包或标投预算
            jsonData.put( "investmentBudget", Util.null2String( rs.getString( "cgbbtys" ) ) );
            //备注
            jsonData.put( "note", Util.null2String( rs.getString( "bz1" ) ) );
            //卖方国别
            jsonData.put( "country", Util.null2String( rs.getString( "mfgbwb" ) ) );
            //预算类型
            jsonData.put( "budgetTypes", Util.null2String( rs.getString( "yslxwb" ) ) );
            //评标_评价办法
            jsonData.put( "evaluationMethod", Util.null2String( rs.getString( "pbpjbf" ) ) );
            //发标日期
            jsonData.put( "invitationDate", Util.null2String( rs.getString( "fbrq" ) ) );
            //开标日期
            jsonData.put( "openingDate", Util.null2String( rs.getString( "kbrq" ) ) );
            //履约担保
            jsonData.put( "performanceGuarantee", Util.null2String( rs.getString( "lydbwb" ) ) );
            //履约阶段
            jsonData.put( "performanceStage", Util.null2String( rs.getString( "lyjdwb" ) ) );
            //履约阶段说明
            jsonData.put( "instructions", Util.null2String( rs.getString( "lyjdsm" ) ) );
            //是否变更
            jsonData.put( "whetherToChange", Util.null2String( rs.getString( "sfybg" ) ) );
            //卖方名称
            jsonData.put( "supplierName", Util.null2String( rs.getString( "gysmc" ) ) );
            //卖方代码
            jsonData.put( "supplierCode", Util.null2String( rs.getString( "gysdm" ) ) );
            //卖方性质
            jsonData.put( "supplierClassify", Util.null2String( rs.getString( "mfxzwb" ) ) );
            //供应商类型
            jsonData.put( "isQualifiedSupplier", Util.null2String( rs.getString( "gyslxwb" ) ) );
            //是否集团内单位
            jsonData.put( "isInUnitCompany", Util.null2String( rs.getString( "sfjtndw" ) ));
            //合同状态
            jsonData.put( "contractStatus", Util.null2String( rs.getString( "htztwb" ) ) );
            //供应商分类
            jsonData.put( "supplierClassification", Util.null2String( rs.getString( "gysflwb" ) ) );
            //具体采购内容简述
            jsonData.put( "purchaseContent", Util.null2String( rs.getString( "jtcgnrjs" ) ) );
            //是否委托招标机构
            jsonData.put( "whetherBidding", Util.null2String( rs.getString( "sfwtzbjgwb" ) ) );
            //采购合同分类
            jsonData.put( "purchaseClass", Util.null2String( rs.getString( "cghtflwb" ) ) );
            //创建人
            jsonData.put( "createBy", Util.null2String( rs.getString( "sqrwb" ) ) );
            //租户编码
            jsonData.put( "tenantCode", "ZDKST" );
            jsonData.put( "status", "rkz" );
            //明细1-收款方对象
            JSONArray payBankArray = new JSONArray();
            rs.executeQuery( "select * from " + tablename + "_dt1 where mainid=?", mainid );
            while (rs.next()) {
                JSONObject payBankJson = new JSONObject();
                //收款方名称
                payBankJson.put( "payeeName", Util.null2String( rs.getString( "skfdw" ) ) );
                //收款方账户
                payBankJson.put( "payeeAccount", Util.null2String( rs.getString( "skfzh" ) ) );
                //开户行
                payBankJson.put( "accountBank", Util.null2String( rs.getString( "khx" ) ) );
                //收款方账户
                payBankJson.put( "repayAcctNo", Util.null2String( rs.getString( "skfzh" ) ) );
                //收款方名称
                payBankJson.put( "repayName", Util.null2String( rs.getString( "skfdw" ) ) );
                //开户行
                payBankJson.put( "branch", Util.null2String( rs.getString( "khx" ) ) );
                //省市
                payBankJson.put( "fulfillmentPlace", Util.null2String( rs.getString( "sswb" ) ) );
                //银联号
                payBankJson.put( "unionpay", Util.null2String( rs.getString( "ylh" ) ) );
                payBankArray.add( payBankJson );
            }
            jsonData.put( "payBank", payBankArray );

            //明细2-投标人/报价人对象
            JSONArray bidderObjArray = new JSONArray();
            rs.executeQuery( "select * from " + tablename + "_dt2 where mainid=?", mainid );
            while (rs.next()) {
                JSONObject bidderObjJson = new JSONObject();
                //投标人/报价人名称
                bidderObjJson.put( "bidderName", Util.null2String( rs.getString( "tbrbjrmc" ) ) );
                //投标人/报价人代码
                bidderObjJson.put( "bidderNumber", Util.null2String( rs.getString( "tbrbjrdm" ) ) );
                bidderObjArray.add( bidderObjJson );
            }
            jsonData.put( "bidderObj", bidderObjArray );
            out.print( ">>>>>jsonData>>>>>" + jsonData.toJSONString()+"<br/>");
            String resultText = InvokeHelper.addPaycont( jsonData.toJSONString() );
            out.print( ">>>>>resultText>>>>>" + resultText+"<br/>" );
            JSONObject resultJson = JSONObject.parseObject( resultText );
            String code = Util.null2String( resultJson.getString( "code" ) );
            String message = Util.null2String( resultJson.getString( "message" ) );
           out.print( "resultJson="+resultJson+"<br/>" );
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
%>
<%!
    /*
     *@Description: 根据表单和字段获取下拉框值
     */
    public static String getSelectItem(int billid, String fieldname, String selectvalue) {
        RecordSet rs = new RecordSet();
        String sql = "select t1.selectvalue,t1.selectname from workflow_selectitem t1 left join workflow_billfield t2\n" +
                "on t1.fieldid=t2.id where abs(t2.billid)=? and t2.fieldname=? and t1.selectvalue=?";
        rs.executeQuery( sql, billid, fieldname, selectvalue );
        rs.next();
        String selectname = Util.null2String( rs.getString( "selectname" ) );
        return selectname;
    }
%>